import Source.chapter1 as c1
import Source.chapter2 as c2
import Source.chapter5 as c5
import Source.chapter7 as c7
import sys

from Source.matrix import Matrix

funcList = [
    [
        # <editor-fold desc="Chapter1 (1~12)">
        c1.inputAndOutput,
        c1.inputAndOutputNameLength,
        c1.getWaterBucketCount,
        c1.calDistance,
        c1.reverseNumber,
        c1.calSum,
        c1.calTriangleArea,
        c1.calInterestRate,
        c1.printTime,
        c1.randomSphere,
        c1.randomComplex,
        c1.diffTime
        # </editor-fold>
    ],
    [
        # <editor-fold desc="Chapter2(List) (13~18)">
        c2.printPrimeNums,
        c2.removeDuplicateValues,
        c2.isIsomorphismString,
        c2.transposeMatrix,
        c2.gradesSort,
        c2.createMagicMatrix
        # </editor-fold>
    ],
    [
        # <editor-fold desc="Chapter3 (19~32)">
        None, None, None, None, None, None, None, None, None, None, None, None, None, None
        # </editor-fold>
    ],
    [
        # <editor-fold desc="Chapter5 (33~40)">
        c5.sumOfFactors,
        c5.reverseNumber,
        c5.getAntiPrimes,
        c5.findMasonPrimes,
        c5.encrypt,
        c5.reverseSentence,
        c5.fibonacci
        # </editor-fold>
    ],
    [
        # <editor-fold desc="Chapter4 (41~47)">
        None, None, None, None, None, None, None
        # </editor-fold>
    ],
    [
        # <editor-fold desc="Chapter2(Tuple & Dict & Set) (48~53)">
        c2.calVariance,
        c2.findKeysIntersectionOfDict,
        c2.findValuesIntersectionOfDict,
        c2.createAndSortEmployees,
        c2.intersectionAndDifference,
        c2.createRandomSetsAndValidate
        # </editor-fold>
    ],
    [
        # <editor-fold desc="Chapter7 (54 ~ 59)">
        c7.copyFile,
        c7.statistics,
        c7.mergeFiles,
        c7.removeWords,
        c7.insertName,
        c7.printSpecifiedLine
        # </editor-fold>
    ]
]

length = sum(len(lst) for lst in funcList)
indexString = input("输入你想运行的题目编号(1~%s)：" % length)

if indexString == "" or indexString is None:
    sys.exit()

index = eval(indexString)

if type(index) != int:
    print("输入的数字不是整数！")
    sys.exit()
elif index < 1 or index > length:
    print("编号超出范围！")
    sys.exit()

c = 0
for i in range(len(funcList)):
    if index - len(funcList[i]) <= 0:
        break
    else:
        c += 1
        index -= len(funcList[i])

if funcList[c][index - 1] is None:
    print("该题目的答案未编写！")
    sys.exit()

inputStr = input("输入参数字典：")
kwargs = eval(inputStr) if inputStr != "" else None

if kwargs is not None:
    funcList[c][index - 1](**kwargs)
else:
    funcList[c][index - 1]()



